package com.general.app.xtgl.action;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;

import com.general.app.xtgl.service.IUserManager;
import com.general.common.action.BaseAction;
import com.general.common.model.QueryModel;
import com.general.common.security.entity.User;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * 用户管理
 * @author Administrator
 *
 */
public class UserAction extends BaseAction implements ModelDriven<User>{

	private static final long serialVersionUID = -5571279048868407604L;
	
	//Action权限标志
	private static final String USER_VIEW = "User:view";
	private static final String USER_ADD = "User:add";

	private User user = new User();
	
	private IUserManager userService;
	
	
	/**
	 * 用户管理列表（打酱油的method）
	 * @return
	 */
	@RequiresPermissions(USER_VIEW)
	public String userList(){
		
		return "userList";
	}
	
	
	
	/**
	 * 增加用户界面（打酱油的method）
	 * @return
	 */
	@RequiresPermissions(USER_ADD)
	public String toAddUser(){
		return "addUser";
	}
	
	
	
	/**
	 * 查询用户 json 数据
	 * @return
	 */
	@RequiresPermissions(USER_VIEW)
	public String getUserList(){
		
		QueryModel queryModel = user.getQueryModel();
		List<User> users = userService.getPagedList(user);
		queryModel.setItems(users);
		ValueStack vs = getValueStack();
		vs.set(DATA, queryModel);
		
		return DATA;
	}

	
	
	/**
	 * 保存（增加）用户
	 * @return
	 */
	@RequiresPermissions(USER_ADD)
	public String addUser(){
		
		return DATA;
	}
	
	
	
	@Override
	public User getModel() {
		return user;
	}


	
	public void setUserService(IUserManager userService) {
		this.userService = userService;
	}

}
